﻿using System;
using System.Linq;
using System.Web.UI.WebControls;
using Models;
using System.Data;


public partial class Moneylist : System.Web.UI.Page
{

    private DataTable dc = new DataTable();
    public string AllCZ = "0", AllGoods = "0", AllTX = "0", AllLR = "0";
    protected void Page_Load(object sender, EventArgs e)
    {
        grdbind();
    }

    public void grdbind()
    {
        using (Entities bll = new Entities())
        {
            var CZList = bll.U_JF.Where(j => j.JGetWay == "充值").Select(j => new
            {
                money = j.JFen,
                time = j.JTime,
                UID = j.JGetWayID,
                way = "充值"
            }).ToArray();

            AllCZ = bll.U_JF.Where(j => j.IsTest == false && (j.JGetWay == "充值" || j.JGetWay == "活动")).Sum(j => j.JFen).ToString();
            if (AllCZ == null)
                AllCZ = "0";


            //var CZList = (from j in bll.U_JF
            //              where (j.JGetWay == "充值")
            //              select new
            //              {
            //                  //money = j.JFen,
            //                  time = j.JTime,
            //                  UID = j.JGetWayID,
            //                  way = "充值"
            //              }).ToList();

            //var GoodList = (from g in bll.S_Order
            //                where g.pay_status == "1" && g.OpayType == "wx"
            //                select new
            //                {
            //                    //money = g.lastPrice,
            //                    time = g.OpayTime,
            //                    UID = g.OopenID,
            //                    way = "购物"
            //                }).ToList();

            var GoodList = bll.S_Order.Where(g => g.pay_status == "1" && g.OpayType == "wx").Select(g => new
            {
                money = g.lastPrice,
                time = g.OpayTime,
                UID = g.OopenID,
                way = "购物"
            }).ToArray();

            AllGoods = bll.S_Order.Where(g => g.pay_status == "1" && g.OpayType == "wx").Sum(g => g.lastPrice).ToString();
            if (string.IsNullOrEmpty(AllGoods))
                AllGoods = "0";

            var TXList = bll.U_TX.Where(t => t.TXstat == 1).Select(t => new
            {
                money = t.TXMoney,
                time = t.TXTime,
                UID = t.UGuid,
                way = "体现"
            }).ToArray();

            AllTX = bll.U_TX.Where(t => t.TXstat == 1).Sum(t => t.TXMoney).ToString();
            if (AllTX == null)
                AllTX = "0";


            AllLR = (Convert.ToDouble(AllCZ) + Convert.ToDouble(AllGoods) - Convert.ToDouble(AllTX)).ToString();

            //PagedDataSource pds = new PagedDataSource();
            //pds.DataSource = CZList.Concat(GoodList).Concat(TXList);  //这里好像一定要Tolist();不然会有点错误；
            //pds.AllowPaging = true;
            //AspNetPager1.RecordCount = CZList.Concat(GoodList).Concat(TXList).Count(); //记录总数；
            //pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
            //pds.PageSize = AspNetPager1.PageSize;

            //this.rptList.DataSource = pds;
            //this.rptList.DataBind();
        }
    }

    //protected void AspNetPager1_PageChanging(object src, Wuqi.Webdiyer.PageChangingEventArgs e)
    //{   //当页面页数改变时，执行这个方法；
    //    AspNetPager1.CurrentPageIndex = e.NewPageIndex;
    //    grdbind();
    //}
}

